package com.molichuxing.gateway.bff.dealer.convertor;

import java.util.ArrayList;
import java.util.List;

import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.gateway.bff.dealer.entity.response.*;
import com.molichuxing.services.business.dto.response.DeviceInfoBizDto;
import org.springframework.beans.BeanUtils;

import com.molichuxing.services.business.dto.response.StoreInfoBizDto;
import com.molichuxing.services.infrastructure.dto.response.DeviceUnionpayParamDto;
import com.molichuxing.services.infrastructure.dto.response.StoreDto;

public class Convert {



	public static List<StoreInfoVo> toStoreInfoVo(List<StoreInfoBizDto> dtoList) {
		List<StoreInfoVo> voList = null;
		if (dtoList != null && !dtoList.isEmpty()) {
			voList = new ArrayList<>();
			for (StoreInfoBizDto storeInfoBizDto : dtoList) {
				voList.add(toStoreInfoVo(storeInfoBizDto));
			}
		}
		return voList;
	}

	public static StoreInfoVo toStoreInfoVo(StoreInfoBizDto storeInfoBizDto) {
		StoreInfoVo beanVo = null;
		if (storeInfoBizDto != null) {
			beanVo = new StoreInfoVo();
			BeanUtils.copyProperties(storeInfoBizDto, beanVo);
			convertStoreInfoVo(beanVo);
		}

		return beanVo;
	}

	public static void convertStoreInfoVo(StoreInfoVo beanVo) {
		double lng= ObjectCastUtil.castDouble(beanVo.getLongitude());
		double lat=ObjectCastUtil.castDouble(beanVo.getDimension());
		double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
		double x = lng - 0.0065, y = lat - 0.006;
		double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
		double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
		lng = z * Math.cos(theta);
		lat = z * Math.sin(theta);
		beanVo.setGaodeLongitude(String.valueOf(lng));
		beanVo.setGaodeDimension(String.valueOf(lat));
	}

	public static List<StoreNameVo> toStoreNameVo(List<StoreDto> dtoList) {
		List<StoreNameVo> voList = null;
		if (dtoList != null && !dtoList.isEmpty()) {
			voList = new ArrayList<>();
			for (StoreDto storeDto : dtoList) {
				voList.add(toStoreNameVo(storeDto));
			}
		}
		return voList;
	}

	public static StoreNameVo toStoreNameVo(StoreDto dto) {
		StoreNameVo beanVo = null;
		if (dto != null) {
			beanVo = new StoreNameVo();
			BeanUtils.copyProperties(dto, beanVo);
		}

		return beanVo;
	}

	public static DeviceUnionpayParamVo toDeviceUnionpayParamVo(DeviceUnionpayParamDto beanDto) {
		DeviceUnionpayParamVo beanVo = null;
		if (beanDto != null) {
			beanVo = new DeviceUnionpayParamVo();
			BeanUtils.copyProperties(beanDto, beanVo);
		}
		return beanVo;
	}

    public static DeviceInfoVo toDeviceInfoVo(DeviceInfoBizDto deviceInfoBizDto ) {
        DeviceInfoVo beanVo = null;
        if (deviceInfoBizDto != null) {
            beanVo = new DeviceInfoVo();
            BeanUtils.copyProperties(deviceInfoBizDto, beanVo);
        }

        return beanVo;
    }


	public static StoreVo toStoreVo(StoreDto storeDto) {
		StoreVo beanVo = null;
		if (storeDto != null) {
			beanVo = new StoreVo();
			BeanUtils.copyProperties(storeDto, beanVo);
			beanVo.setStoreStatus(storeDto.getStatus());
		}

		return beanVo;
	}
}
